﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace blackhouse.WebNemo.Business.Groups {
    public abstract class GroupExtension {

        #region Fields

        private static GroupExtension nullExtension = new NULLGroupExtension();
        protected IGroup group;

        #endregion

        #region Properties

        public static GroupExtension NULL {
            get { return nullExtension; }
        }

        #endregion

        #region Constructors

        public GroupExtension(IGroup group) {
            this.group = group;
        }

        #endregion

        #region Methods

        public abstract bool ShouldUseThisColumnInEditor(GroupColumn column);

        public static GroupExtension GetGroupExtension(IGroup group) {
            string extName = group.GetGroupExtensionName();
            if (String.IsNullOrEmpty(extName)) return NULL;
            Type t = Type.GetType(extName, false);
            if (t == null) return NULL;
            GroupExtension extension = null;
            try {
                extension = Activator.CreateInstance(t, group) as GroupExtension;
            }
            catch {
                extension = NULL;
            }
            return extension;
        }

        #endregion

    }

    public sealed class NULLGroupExtension : GroupExtension {

        #region Constructor

        public NULLGroupExtension()
            : base(null) { }

        #endregion

        #region Methods

        public override bool ShouldUseThisColumnInEditor(GroupColumn column) {
            return !column.HideForEdition;
        }

        #endregion

    }

}
